//
//  WFDesignerCell.m
//  谷居
//
//  Created by dllo on 16/6/18.
//  Copyright © 2016年 刘万方. All rights reserved.
//

#import "WFDesignerCell.h"
#import "WFUIView.h"
#import "WFLabel.h"
#import "WFImageView.h"
#import "Masonry.h"
#import "UIImageView+AFNetworking.h"

@interface WFDesignerCell ()

@property (nonatomic, retain) WFImageView *photoImageView;

@property (nonatomic, retain) WFLabel *topLabel;

@property (nonatomic, retain) WFLabel *midLabel;

@property (nonatomic, retain) WFLabel *caseLabel;

@property (nonatomic, retain) WFLabel *guideLabel;

@property (nonatomic, retain) WFLabel *shareLabel;

@property (nonatomic, retain) WFImageView *goldenImageView;

@property (nonatomic, retain) WFImageView *arrowImageView;


@end
@implementation WFDesignerCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createCell];
        
    }
    return self;
}


- (void)createCell {
    _photoImageView = [WFImageView new];
    [self.contentView addSubview:_photoImageView];
    [_photoImageView release];
    
    
    _topLabel = [WFLabel new];
    [self.contentView addSubview:_topLabel];
    [_topLabel release];
    
    
    _midLabel = [WFLabel new];
    [self.contentView addSubview:_midLabel];
    [self.contentView addSubview:_midLabel];
    [_midLabel release];
    
    
    _goldenImageView = [WFImageView new];
    [self.contentView addSubview:_goldenImageView];
    [_goldenImageView release];
    
    
    _caseLabel = [WFLabel new];
    [self.contentView addSubview:_caseLabel];
    [_caseLabel release];
    
    
    _guideLabel = [WFLabel new];
    [self.contentView addSubview:_guideLabel];
    [_guideLabel release];
    
    _shareLabel = [WFLabel new];
    [self.contentView addSubview:_shareLabel];
    [_shareLabel release];
    
    _arrowImageView = [WFImageView new];
    [self.contentView addSubview:_arrowImageView];
    [_arrowImageView release];
    
    
    
}



- (void)layoutSubviews {
    [super layoutSubviews];
    
    
    [_photoImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(15);
        make.centerY.equalTo(self.contentView);
        make.size.mas_equalTo(CGSizeMake(40, 40));
    }];
    _photoImageView.backgroundColor = [UIColor redColor];
    _photoImageView.layer.cornerRadius = 20;
    _photoImageView.layer.masksToBounds = YES;
    [_photoImageView setImageWithURL:[NSURL URLWithString:_userImageModel.small] placeholderImage:[UIImage imageNamed:@"placeholder-avatar"]];
    
    
    [_topLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_photoImageView.mas_right).offset(15);
        make.top.equalTo(self.contentView).offset(15);
    }];
    _topLabel.font = [UIFont systemFontOfSize:15];
    _topLabel.text = _professionalModel.userName;
    [_topLabel sizeToFit];
    _topLabel.frame = CGRectMake(0, 0, 120, 20);
    
    
    [_midLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_topLabel.mas_left);
        make.top.equalTo(_topLabel.mas_bottom).offset(10);
    }];
    
    _midLabel.frame = CGRectMake(0, 0, 120, 20);
    NSString *sex = [NSString new];
    if (_professionalModel.sex == 0) {
        sex = @"女";
    } else {
        sex = @"男";
    }
    NSString *midStr = [NSString stringWithFormat:@"%@|%@%@", sex, _professionalModel.province, _professionalModel.city];
    _midLabel.text = midStr;
//    _midLabel.font = FONT(15);
    _midLabel.font = FONT(13);
    [_midLabel sizeToFit];
    
    
    
    [_caseLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_topLabel.mas_left);
        make.top.equalTo(_midLabel.mas_bottom).offset(10);
    }];
    
    _caseLabel.frame = CGRectMake(0, 0, 30, 20);
//    _caseLabel.backgroundColor = [UIColor redColor];
    NSString *caseStr =[NSString stringWithFormat:@"案例:%ld", _professionalModel.projectNum];
#pragma mark - 改变label当中的属性来改变某一字段的颜色等. 
    NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:caseStr];
    [str addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:0.3784 green:0.1648 blue:1.0 alpha:1.0] range:NSMakeRange(2, str.length - 2)];
    _caseLabel.attributedText = str;
    [str release];
    _caseLabel.font = FONT(15);
    [_caseLabel sizeToFit];
    
    
    [_guideLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_caseLabel.mas_right).offset(10);
        make.centerY.equalTo(_caseLabel);
        
    }];
    _guideLabel.frame = CGRectMake(0, 0, 30, 20);
    NSString *guideStr = [NSString stringWithFormat:@"攻略:%ld", _professionalModel.strategyNum];
    NSMutableAttributedString *guideAttributeStr = [[NSMutableAttributedString alloc] initWithString:guideStr];
    [guideAttributeStr addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:0.3784 green:0.1648 blue:1.0 alpha:1.0] range:NSMakeRange(2, guideAttributeStr.length - 2)];
    _guideLabel.attributedText = guideAttributeStr;
    [guideAttributeStr release];
    _guideLabel.font = FONT(15);
    [_guideLabel sizeToFit];
    
    
    [_shareLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_guideLabel.mas_right).offset(10);
        make.centerY.equalTo(_caseLabel);
        
    }];
    _shareLabel.frame = CGRectMake(0, 0, 30, 20);
    NSString *shareStr = [NSString stringWithFormat:@"分享:%ld", _professionalModel.photoNum];
    NSMutableAttributedString *shareAttributeStr = [[NSMutableAttributedString alloc] initWithString:shareStr];
    [shareAttributeStr addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:0.3784 green:0.1648 blue:1 alpha:1] range:NSMakeRange(2, shareAttributeStr.length - 2)];
    _shareLabel.attributedText = shareAttributeStr;
    [shareAttributeStr release];
    _shareLabel.font = FONT(15);
    [_shareLabel sizeToFit];
    
    
    
    [_arrowImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.right.equalTo(self.contentView).offset(-10);
        make.centerY.equalTo(self.contentView);
        make.size.mas_equalTo(CGSizeMake(25, 25));
    }];
    _arrowImageView.image = [UIImage imageNamed:@"右箭头.png"];
    
    
    
    
}


- (void)dealloc {
    [super dealloc];
    
}
@end
